home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / kiss10.zip / KISS10.C < prev   
C/C++ Source or Header  |  1992-07-25  |  8KB  |  212 lines

  1. Organization: Texas Christian University
  2. Message-ID: 1992Jul25.072627.23437@riogrande.cs.tcu.edu
  3. Newsgroups: alt.binaries.pictures.erotica,alt.binaries.pictures.erotica.d,alt.binaries.pictures.d
  4.  
  5.  
  6.  
  7.  
  8. KISS-1.0.C
  9.  
  10. This is a C program that trims headers/footers and does uudecoding at the
  11. same time.  This application has some advantages over the programs that have
  12. appeared on this net.  For example, uuconvert.c , uudecode.c & eek.c , etc.
  13. Also, it can handle an unlimited number of input files including standard input
  14. and multiple parts in a single file.
  15. Further, it handles special cases such as those that happen to USKT-76.JPG in which the end
  16. marker is placed in a separate artical.  These net programs uuconvert.c, eek.c, and others
  17. will crash because this special case is not taken into consideration.
  18. This program has undergone extensive testing without failure to date.  All you need
  19. to do is to make sure all articals used are in order.  Say, artical#1, artical#2, ...
  20.  
  21. This program is being written for your convenience.  Feel free to distribute
  22. copies.  If you find any bugs or have any comments please respond accordingly.
  23. I spent an entire sunday night to write it, without going on a date.  Oh, boy,
  24. I miss kissing those hot lips in the summer night.  :-) :-)
  25.  
  26. FLAMES -->> GAMMA.IS.TCU.EDU
  27.  
  28. KEVIN YANG
  29. SANANTONIO.CS.TCU.EDU
  30.  
  31.  
  32. --------------CUT HERE---------------CUT HERE----------------CUT HERE----------
  33.  
  34.  
  35. /*
  36.  * kiss-1.0.c
  37.  * AUTHOR: Kevin Yang
  38.  *
  39.  * This C program (UNIX) takes an unlimited number of uuencoded files,
  40.  * and trims headers/footers.  The uuencoded lines are decoded and written 
  41.  * to specific output files.
  42.  *
  43.  * To compile: "cc -O -o kiss kiss-1.0.c".
  44.  *
  45.  */
  46.  
  47.  
  48. #include <stdio.h>
  49. #include <ctype.h>
  50.  
  51. #define Author "Kevin Yang"
  52. #define PName "KiSS"
  53. #define DEC(C)        (((C) - ' ') & 077)
  54. #define LEN 128
  55.  
  56. /* most variables are declared globally, in order to
  57.  * speed up function calls.
  58.  */
  59.  
  60. static char input_buf[LEN], a[LEN], b[LEN], dest[LEN];
  61. static char *buf = input_buf, *ap = a, *bp = b, *tmp, *p;
  62. static int len, mode, newdata, endmark, hasdata, bquote, i, x, y, z;
  63. static unsigned siz = sizeof(input_buf);
  64. static FILE *ofp;
  65.  
  66.  
  67.  
  68. main(argc, argv)
  69. int argc;
  70. char *argv[];
  71. {
  72.       FILE *ifp;
  73.  
  74.       if (argc < 2)  {
  75.               KissFile(stdin);                                /* standard input */
  76.       } else  {
  77.               for (;--argc && ++argv; ) {
  78.                       if (! (ifp  = fopen(*argv,"r"))) {
  79.                               fprintf(stderr, "%s: %s: ", PName, *argv);
  80.                               perror(ifp);
  81.                               continue;
  82.                       }
  83.                       KissFile(ifp);
  84. /*                    remove(*argv);  */              /* uncomment this when you want to save spaces,*/
  85.                                                       /* it simply delete the input file             */
  86.                       fclose(ifp);
  87.               }
  88.       }
  89.       printf("\tKiss me, horny ...\n");
  90. }  /* main */
  91.  
  92.  
  93.  
  94. /* This function "kiss" the input file until all articals
  95.  * are decoded.
  96.  */
  97.  
  98. int KissFile(ifp)
  99. FILE *ifp;
  100. {
  101.       hasdata = bquote = 0;
  102.       while (fgets(buf, siz, ifp))  {
  103.               while(1) {
  104.                       if (!strncmp(buf,"begin ",6) && isdigit(buf[6]))  {
  105.                               hasdata = 1;                    /* yes, we found valid begin line */
  106.                               break;
  107.                       }
  108.                       if (!fgets(buf, siz, ifp)) {
  109.                               if (!hasdata) fprintf(stderr, "\t%s: No begin line\n", PName);
  110.                               return (0);
  111.                       }
  112.               }
  113.  
  114.               if (sscanf(buf, "begin %o %s", &mode, dest) != 2)  {            /* extract filename and file-mode       */
  115.                       fprintf(stderr, "%s: %s: Missing filename or mode\n", PName, buf);
  116.                       continue;                                               /* try again when error occur           */
  117.               }
  118.  
  119.               if ((ofp = fopen(dest, "w")) == NULL) {                         /* prepare output file                  */
  120.                       fprintf(stderr, "%s: %s: ", PName, dest);
  121.                       perror(ifp);
  122.                       continue;
  123.               }
  124.  
  125.               chmod(dest, mode);                                              /* set file-mode                        */
  126.               fprintf(stdout, "Extracting  <%s>\t\t-- ", dest);
  127.  
  128.               while (fgets(buf,siz,ifp)) {
  129.                       if ( (endmark = !strncmp(buf, "end", 3))
  130.                               || (newdata = !strncmp(buf, "begin ", 6)
  131.                               && isdigit(buf[6])) )  {
  132.                               if (newdata)  {                         /* no end marker*/
  133.                                       fseek(ifp, -strlen(buf), 1);    /* reset input stream */
  134.                               }
  135.                               KissLin(ap,ofp);
  136.                               break;
  137.                       }
  138.                       len = strlen(buf);
  139.                       if (*buf != 'M' || len < 60 || len > 70
  140.                               || !strncmp(buf, "Message-ID:", 11))  {
  141.                               if (*buf == '`')  {                     /* "`" char exist */
  142.                                       bquote = 1;
  143.                                       KissLin(bp, ofp);               /* or end marker comes  */
  144.                                       break;                          /* from another file.   */
  145.                               }                                       /* This is a tricky case*/
  146.                               tmp = ap;
  147.                               ap = bp;
  148.                               bp = buf;
  149.                               buf = tmp;
  150.                               continue;
  151.                       }
  152.                       KissLin(buf, ofp);
  153.               }
  154.               fclose(ofp);
  155.  
  156.               fprintf(stdout, "Done\n");
  157.               if ((newdata || !endmark) && !bquote) fprintf(stderr, "\t%s: No end line\n", PName);
  158.       }
  159. }
  160.  
  161.  
  162.  
  163. /* This function decodes one line of information.
  164.  * C codes are slightly different from those of uuconvert.c
  165.  * or uudecode.c.  I use pointers instead of array indices
  166.  * to avoid time consuming address multiplications.  The 
  167.  * condition tests are modified and eliminates 2 tests
  168.  * for every 4 bytes.  Characters are decoded only when
  169.  * one of the three conditions matches, in which complicated
  170.  * mathmatical computation are eliminated for the last few
  171.  * bytes.
  172.  * I hope this can speed up the process!
  173.  */
  174. KissLin(str)
  175. char *str;
  176. {
  177.       i = DEC(*str);
  178.       p = ++str;
  179.       while (i > 0)  {
  180.               if (i >= 3)  {
  181.                       x  = (DEC(*p) << 2);    p++;
  182.                       x |= (DEC(*p) >> 4);
  183.                       y  = (DEC(*p) << 4);    p++;
  184.                       y |= (DEC(*p) >> 2);
  185.                       z  = (DEC(*p) << 6);    p++;
  186.                       z |= (DEC(*p));
  187.                       putc(x, ofp);
  188.                       putc(y, ofp);
  189.                       putc(z, ofp);
  190.               } else {
  191.                       if (i >= 2)  {
  192.                               x  = (DEC(*p) << 2);    p++;
  193.                               x |= (DEC(*p) >> 4);
  194.                               y  = (DEC(*p) << 4);    p++;
  195.                               y |= (DEC(*p) >> 2);
  196.                               putc(x, ofp);
  197.                               putc(y, ofp);
  198.                       } else {
  199.                               if (i >= 1)  {
  200.                                       x  = (DEC(*p) << 2);    p++;
  201.                                       x |= (DEC(*p) >> 4);
  202.                                       putc(x, ofp);
  203.                               }  /* if  */
  204.                       }  /* else  */
  205.               }  /* else  */
  206.  
  207.               str += 4;
  208.               p = str;
  209.               i -= 3;
  210.       }  /* while  */
  211. }  /* KissLin */
  212.